package com.haitaoit.chengquan.module.home.activity.maintenance;

import android.content.Intent;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.mapapi.search.core.SearchResult;
import com.baidu.mapapi.search.geocode.GeoCodeOption;
import com.baidu.mapapi.search.geocode.GeoCodeResult;
import com.baidu.mapapi.search.geocode.GeoCoder;
import com.baidu.mapapi.search.geocode.OnGetGeoCoderResultListener;
import com.baidu.mapapi.search.geocode.ReverseGeoCodeResult;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.haitaoit.chengquan.R;
import com.haitaoit.chengquan.baiduservice.LocationService;
import com.haitaoit.chengquan.base.QBaseActivity;
import com.haitaoit.chengquan.main.MianButtonActivity;
import com.haitaoit.chengquan.module.home.activity.fabu.ConsumptiveServiceActivity;
import com.haitaoit.chengquan.module.home.activity.fabu.EquipmentSixServiceActivity;
import com.haitaoit.chengquan.module.home.activity.fabu.GroupServiceActivity;
import com.haitaoit.chengquan.module.home.activity.fabu.QSendNeedActivity;
import com.haitaoit.chengquan.module.home.activity.fabu.QSendServiceActivity;
import com.haitaoit.chengquan.module.home.activity.fabu.ReformServiceActivity;
import com.haitaoit.chengquan.module.home.activity.fabu.SecondHandServiceActivity;
import com.haitaoit.chengquan.module.home.activity.fabu.ToolServiceActivity;
import com.haitaoit.chengquan.module.home.activity.fabu.WorkingServiceActivity;
import com.haitaoit.chengquan.module.home.activity.maintenance.adapter.FacilityMainenanceAdapter;
import com.haitaoit.chengquan.module.home.model.FacilityMainenanceModel;
import com.haitaoit.chengquan.module.login.LoginActivity;
import com.haitaoit.chengquan.ui.equipment.activity.CheagedNeedActivity;
import com.haitaoit.chengquan.ui.equipment.activity.HCSendNeedActivity;
import com.haitaoit.chengquan.ui.equipment.activity.JCSendNeedActivity;
import com.haitaoit.chengquan.ui.equipment.activity.JGDDAddRequirementActivity;
import com.haitaoit.chengquan.ui.equipment.activity.PJSendNeedActivity;
import com.haitaoit.chengquan.ui.equipment.activity.SBWXAddRequirementActivity;
import com.haitaoit.chengquan.ui.equipment.activity.SecondHandActivity;
import com.haitaoit.chengquan.utils.Constant;
import com.haitaoit.chengquan.utils.DateTimeUtil;
import com.haitaoit.chengquan.utils.GetSign;
import com.haitaoit.chengquan.utils.HttpUtilsSingle;
import com.haitaoit.chengquan.utils.NameValuePairSign;
import com.haitaoit.chengquan.utils.PreferenceUtils;
import com.haitaoit.chengquan.utils.ToastUtils;
import com.haitaoit.chengquan.view.MyListView;
import com.haitaoit.chengquan.view.PullToRefreshBase;
import com.haitaoit.chengquan.view.PullToRefreshScrollView;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class QFacilityMaintenanceActivity extends QBaseActivity implements PullToRefreshBase.OnRefreshListener<ScrollView> {

    @ViewInject(R.id.pull_to_refresh_scrollview)
    PullToRefreshScrollView pull_to_refresh_scrollview;
    @ViewInject(R.id.search_et)
    EditText                search_et;
    @ViewInject(R.id.back)
    ImageView               back;
    @ViewInject(R.id.tv_public)
    TextView                tv_public;
    @ViewInject(R.id.title)
    TextView                title;
    //距离
    @ViewInject(R.id.distance)
    RelativeLayout          distance;
    //距离上箭头
    @ViewInject(R.id.distance_up)
    ImageView               distance_up;
    //距离下箭头
    @ViewInject(R.id.distance_down)
    ImageView               distance_down;


    //信誉
    @ViewInject(R.id.reputation)
    RelativeLayout reputation;
    //信誉上箭头
    @ViewInject(R.id.reputation_up)
    ImageView      reputation_up;
    //信誉下箭头
    @ViewInject(R.id.reputation_down)
    ImageView      reputation_down;

    //评价
    @ViewInject(R.id.evaluate)
    RelativeLayout evaluate;
    //评价上箭头
    @ViewInject(R.id.evaluate_up)
    ImageView      evaluate_up;
    //评价下箭头
    @ViewInject(R.id.evaluate_down)
    ImageView      evaluate_down;


    private ScrollView   mScrollView;
    private LinearLayout null_information_layout;
    private MyListView   listView;


    private boolean isFrist = true;
    private int     page    = 1;
    private FacilityMainenanceAdapter adapter;
    private int title_type = 1, type_id_ser = 0, type_id_need = 0;


    private int    type_id;
    private int    my_type;
    private String account_type;


    private boolean isDistance   = true;
    private boolean isReputation = true;
    private boolean isEvaluate   = true;

    //TODO:排序方式,作为参数传递到rui中
    private String sort      = "0";
    private String deriction = "0";

    @Override
    public int getContentView() {
        return R.layout.activityq_facility_maintenance;
    }

    @Override
    public void initView() {

        ViewUtils.inject(this);

        account_type = PreferenceUtils.getPrefString("account_type", "");
        View view = LayoutInflater.from(this).inflate(R.layout.scrollview_listview_layout, null);
        null_information_layout = (LinearLayout) view.findViewById(R.id.null_information_layout);
        listView = (MyListView) view.findViewById(R.id.scrollview_listview);

        pull_to_refresh_scrollview.setPullLoadEnabled(true);
        pull_to_refresh_scrollview.setPullRefreshEnabled(true);
        pull_to_refresh_scrollview.setOnRefreshListener(this);
        pull_to_refresh_scrollview.setLastUpdatedLabel(DateTimeUtil
                .getFormatDateTime(DateTimeUtil.getCurrTimestamp()));
        mScrollView = pull_to_refresh_scrollview.getRefreshableView();
        mScrollView.setFillViewport(true);
        mScrollView.setVerticalScrollBarEnabled(false);
        mScrollView.addView(view);

        showDailog("正在加载数据，请稍等....");
        adapter = new FacilityMainenanceAdapter(this);
        adapter.setType(title_type);
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                Intent intent = new Intent();
                if (title_type == 1) {// 找服务
                    PreferenceUtils.setPrefString("type_id_need_7", type_id + "");
                    intent.setClass(QFacilityMaintenanceActivity.this, ServerDetailActivity.class);

                } else if (title_type == 2) {// 找需求
                    PreferenceUtils.setPrefString("see",type_id+"");
                    intent.setClass(QFacilityMaintenanceActivity.this, SeachDemandActivity.class);

                }
                intent.putExtra("id", adapter.getList().get(position).getId());
                startActivity(intent);
            }
        });

        //根据需求商不能发布服务，服务商不能发布需求的原则
        String account_type = PreferenceUtils.getPrefString("account_type", "");

        if (TextUtils.equals(account_type, "1")) {
            tv_public.setVisibility(View.GONE);
        } else {
            tv_public.setVisibility(View.VISIBLE);
        }


        type_id = getIntent().getIntExtra("type_id", 0);
        my_type = getIntent().getIntExtra("my_type", 0);

        if (type_id == 1) {
            title.setText("设备维修");
            type_id_need = 1;
            type_id_ser = 1;

        } else if (type_id == 2) {
            type_id_need = 5;
            type_id_ser = 2;
            title.setText("加工订单/共享机床");
        } else if (type_id == 3) {
            type_id_ser = 3;
            type_id_need = 2;
            title.setText("机床耗材");
        } else if (type_id == 4) {
            type_id_need = 4;
            type_id_ser = 4;
            title.setText("机床配件");
        } else if (type_id == 5) {
            type_id_need = 3;
            type_id_ser = 5;
            title.setText("机床组立");
        } else if (type_id == 6) {
            type_id_need = 6;
            type_id_ser = 6;
            title.setText("二手设备买卖");
        } else if (type_id == 7) {
            type_id_need = 7;
            type_id_ser = 7;
            title.setText("二手设备改造");
        }
        //默认初始化箭头方向
        initBigin();
    }
    private void initBigin() {
        //距离
        distance_up.setImageResource(R.mipmap.img33_1);
        distance_down.setImageResource(R.mipmap.img34);
        //信誉
        reputation_up.setImageResource(R.mipmap.img33_1);
        reputation_down.setImageResource(R.mipmap.img34);
        //评价
        evaluate_up.setImageResource(R.mipmap.img33_1);
        evaluate_down.setImageResource(R.mipmap.img34);
    }

    private final String TAG = "MainActivity";
    private LocationService locationService;
    private GeoCoder        mSearch;
    private String mLatitude  = 31.249158854340077 + "";
    private String mLongitude = 121.4878971501004 + "";


    private BDLocationListener          mListener = new BDLocationListener() {
        @Override
        public void onReceiveLocation(BDLocation location) {

            //定位成功
            if (null != location && location.getLocType() != BDLocation.TypeServerError) {// 定位成功
                PreferenceUtils.setPrefString("location_city", location.getCity());

                mSearch = GeoCoder.newInstance();
                mSearch.geocode(new GeoCodeOption().city("").address(location.getCity()));
                mSearch.setOnGetGeoCodeResultListener(listener);
                locationService.unregisterListener(mListener);// 注销掉监听
                locationService.stop();// 停止定位服务
                PreferenceUtils.setPrefString("location_city", location.getCity());
            } else {
                // 定位失败
                //添加定位功能.获取当前位置
                String latitudeD = PreferenceUtils.getPrefString("latitude", "");
                String longitudeD = PreferenceUtils.getPrefString("longitude", "");
                if (!TextUtils.isEmpty(latitudeD) && !TextUtils.isEmpty(longitudeD)) {
                    mLatitude = latitudeD;
                    mLongitude = longitudeD;
                }
                httpGetdemand_list(Constant.Getservice_list);
            }
        }
    };
    private OnGetGeoCoderResultListener listener  = new OnGetGeoCoderResultListener() {
        public void onGetGeoCodeResult(GeoCodeResult result) {
            if (result == null || result.error != SearchResult.ERRORNO.NO_ERROR) {
                //地址编译失败
                //添加定位功能.获取当前位置
                String latitudeD = PreferenceUtils.getPrefString("latitude", "");
                String longitudeD = PreferenceUtils.getPrefString("longitude", "");
                if (!TextUtils.isEmpty(latitudeD) && !TextUtils.isEmpty(longitudeD)) {
                    mLatitude = latitudeD;
                    mLongitude = longitudeD;
                }
                httpGetdemand_list(Constant.Getservice_list);
            } else {
                //地址编译成功
                // 获取地理编码结果
                Log.e("tag", "result1:" + result.getAddress() + "====" + result.getLocation().latitude + "-----" + result.getLocation().longitude);
                mLatitude = result.getLocation().latitude + "";
                mLongitude = result.getLocation().longitude + "";
                PreferenceUtils.setPrefString("latitude", mLatitude + "");
                PreferenceUtils.setPrefString("longitude", mLongitude + "");
                httpGetdemand_list(Constant.Getservice_list);
            }
        }

        @Override
        public void onGetReverseGeoCodeResult(ReverseGeoCodeResult reverseGeoCodeResult) {
            if (reverseGeoCodeResult == null || reverseGeoCodeResult.error != SearchResult.ERRORNO.NO_ERROR) {
                //没有找到检索结果
            } else {// 获取反向地理编码结果
                Log.e("tag", "reverseGeoCodeResult1:" + reverseGeoCodeResult.toString());
            }

        }
    };

    @Override
    public void initData() {

        //首先获取当前的地理位置
        locationService = new LocationService(this);
        locationService.registerListener(mListener);
        locationService.start();// 定位SDK
    }

    @Override
    public void initEvent() {
        //back.setOnClickListener(this);
        //tv_public.setOnClickListener(this);
        //        search_img.setOnClickListener(this);
        //        search_server.setOnClickListener(this);
        //        search_maintenance.setOnClickListener(this);
    }

    @Override
    protected void updateUI(Message msg) {

    }

    //距离          //信誉        //评价
    @OnClick({R.id.back, R.id.tv_public, R.id.search_img, R.id.search_server, R.id.search_maintenance, R.id.distance, R.id.reputation, R.id.evaluate})
    public void onClick(View v) {
        //没有排序方向
        deriction = "0";
        //不排序
        sort = "0";
        //switch (v.getId()){
        //    case R.id.back:
        //        finish();
        //        break;
        //    case R.id.tv_public:
        //        break;
        //    }
        Intent intent = new Intent();
        switch (v.getId()) {
            case R.id.back:
                intent.setClass(QFacilityMaintenanceActivity.this, MianButtonActivity.class);
                startActivity(intent);
                finish();
                break;
            case R.id.tv_public:

                intent.putExtra("type_id", type_id);
                //            int type_id = getIntent().getIntExtra("type_id", 0);

                if (title_type == 1) {
                    // 发布服务
                    switch (my_type) {
                        case 1:
                            if (TextUtils.isEmpty(PreferenceUtils.getPrefString("user_id", ""))) {
                                Intent intentA = new Intent(this, LoginActivity.class);
                                intentA.putExtra("tag", "0");
                                startActivity(intentA);
                            } else {
                                //发布设备维修
                                intent.setClass(QFacilityMaintenanceActivity.this, ReformServiceActivity.class);
                            }
                            break;
                        case 2:
                            if (TextUtils.isEmpty(PreferenceUtils.getPrefString("user_id", ""))) {
                                Intent intentA = new Intent(this, LoginActivity.class);
                                intentA.putExtra("tag", "0");
                                startActivity(intentA);
                            } else {
                                //加工订单
                                intent.setClass(QFacilityMaintenanceActivity.this, WorkingServiceActivity.class);
                            }
                            break;
                        case 3:
                            if (TextUtils.isEmpty(PreferenceUtils.getPrefString("user_id", ""))) {
                                Intent intentA = new Intent(this, LoginActivity.class);
                                intentA.putExtra("tag", "0");
                                startActivity(intentA);
                            } else {
                                //机床耗材
                                intent.setClass(QFacilityMaintenanceActivity.this, ConsumptiveServiceActivity.class);
                            }
                            break;
                        case 4:
                            if (TextUtils.isEmpty(PreferenceUtils.getPrefString("user_id", ""))) {
                                Intent intentA = new Intent(this, LoginActivity.class);
                                intentA.putExtra("tag", "0");
                                startActivity(intentA);
                            } else {
                                //机床配件
                                intent.setClass(QFacilityMaintenanceActivity.this, ToolServiceActivity.class);
                            }
                            break;
                        case 5:
                            if (TextUtils.isEmpty(PreferenceUtils.getPrefString("user_id", ""))) {
                                Intent intentA = new Intent(this, LoginActivity.class);
                                intentA.putExtra("tag", "0");
                                startActivity(intentA);
                            } else {
                                //机床组立
                                intent.setClass(QFacilityMaintenanceActivity.this, GroupServiceActivity.class);
                            }
                            break;
                        case 6:
                            if (TextUtils.isEmpty(PreferenceUtils.getPrefString("user_id", ""))) {
                                Intent intentA = new Intent(this, LoginActivity.class);
                                intentA.putExtra("tag", "0");
                                startActivity(intentA);
                            } else {
                                //二手设备
                                intent.setClass(QFacilityMaintenanceActivity.this, SecondHandServiceActivity.class);
                            }
                            break;
                        case 7:
                            if (TextUtils.isEmpty(PreferenceUtils.getPrefString("user_id", ""))) {
                                Intent intentA = new Intent(this, LoginActivity.class);
                                intentA.putExtra("tag", "0");
                                startActivity(intentA);
                            } else {
                                //设备改造ok
                                intent.setClass(QFacilityMaintenanceActivity.this, EquipmentSixServiceActivity.class);
                            }
                            break;
                        default:
                            intent.setClass(QFacilityMaintenanceActivity.this, QSendServiceActivity.class);
                            break;
                    }


                } else if (title_type == 2) {

                    // 发布需求
                    switch (my_type) {
                        case 1:
                            if (TextUtils.isEmpty(PreferenceUtils.getPrefString("user_id", ""))) {
                                Intent intentA = new Intent(this, LoginActivity.class);
                                intentA.putExtra("tag", "0");
                                startActivity(intentA);
                            } else {
                                intent.setClass(QFacilityMaintenanceActivity.this, SBWXAddRequirementActivity.class);
                            }
                            break;
                        case 2:
                            if (TextUtils.isEmpty(PreferenceUtils.getPrefString("user_id", ""))) {
                                Intent intentA = new Intent(this, LoginActivity.class);
                                intentA.putExtra("tag", "0");
                                startActivity(intentA);
                            } else {
                                intent.setClass(QFacilityMaintenanceActivity.this, JGDDAddRequirementActivity.class);
                            }
                            break;
                        case 3:
                            if (TextUtils.isEmpty(PreferenceUtils.getPrefString("user_id", ""))) {
                                Intent intentA = new Intent(this, LoginActivity.class);
                                intentA.putExtra("tag", "0");
                                startActivity(intentA);
                            } else {
                                //机床耗材
                                intent.setClass(QFacilityMaintenanceActivity.this, HCSendNeedActivity.class);
                            }
                            break;
                        case 4:
                            if (TextUtils.isEmpty(PreferenceUtils.getPrefString("user_id", ""))) {
                                Intent intentA = new Intent(this, LoginActivity.class);
                                intentA.putExtra("tag", "0");
                                startActivity(intentA);
                            } else {
                                //机床配件
                                intent.setClass(QFacilityMaintenanceActivity.this, PJSendNeedActivity.class);
                            }
                            break;
                        case 5:
                            if (TextUtils.isEmpty(PreferenceUtils.getPrefString("user_id", ""))) {
                                Intent intentA = new Intent(this, LoginActivity.class);
                                intentA.putExtra("tag", "0");
                                startActivity(intentA);
                            } else {
                                //机床组立
                                intent.setClass(QFacilityMaintenanceActivity.this, JCSendNeedActivity.class);
                            }
                            break;
                        case 6:
                            if (TextUtils.isEmpty(PreferenceUtils.getPrefString("user_id", ""))) {
                                Intent intentA = new Intent(this, LoginActivity.class);
                                intentA.putExtra("tag", "0");
                                startActivity(intentA);
                            } else {
                                //二手设备买卖
                                intent.setClass(QFacilityMaintenanceActivity.this, SecondHandActivity.class);
                            }
                            break;
                        case 7:
                            if (TextUtils.isEmpty(PreferenceUtils.getPrefString("user_id", ""))) {
                                Intent intentA = new Intent(this, LoginActivity.class);
                                intentA.putExtra("tag", "0");
                                startActivity(intentA);
                            } else {
                                //设备改造
                                intent.setClass(QFacilityMaintenanceActivity.this, CheagedNeedActivity.class);
                            }
                            break;
                        default:
                            intent.setClass(QFacilityMaintenanceActivity.this, QSendNeedActivity.class);
                            break;
                    }
                }
                startActivityForResult(intent, 15);
                break;
            case R.id.search_img:
                isFrist = true;
                page = 1;
                if (title_type == 1) {
                    httpGetdemand_list(Constant.Getservice_list);
                } else if (title_type == 2) {
                    httpGetdemand_list(Constant.Getdemand_list);
                }
                break;
            //找服务
            case R.id.search_server:
                isDistance = true;
                isReputation = true;
                isEvaluate = true;
                sort = "0";
                deriction = "0";
                //默认初始化箭头方向
                initBigin();

                title_type = 1;
                if (TextUtils.equals(account_type, "1")) {
                    tv_public.setVisibility(View.GONE);
                } else {
                    tv_public.setVisibility(View.VISIBLE);
                }

                //            if(account_type!=null&&account_type.equals("1")){
                //                setRightShow(0, R.string.app_empty);
                //            }

                // 0全部2加工订单3机床耗材4机床配件5机床组立6二手设备买卖7二手设备改造
                // 0全部1设备维修2机床耗材3机床组立4机床配件5加工订单6二手货设备买卖7二手货设置改造
                if (type_id == 1) {
                    type_id_ser = 1;
                } else if (type_id == 2) {
                    type_id_ser = 2;
                } else if (type_id == 3) {
                    type_id_ser = 3;
                } else if (type_id == 4) {
                    type_id_ser = 4;
                } else if (type_id == 5) {
                    type_id_ser = 5;
                } else if (type_id == 6) {
                    type_id_ser = 6;
                } else if (type_id == 7) {
                    type_id_ser = 7;
                }
                adapter.setType(title_type);
                isFrist = true;
                page = 1;
                showDailog("正在加载中....");
                httpGetdemand_list(Constant.Getservice_list);
                break;
            //找需求
            case R.id.search_maintenance:
                isDistance = true;
                isReputation = true;
                isEvaluate = true;
                //默认初始化箭头方向
                initBigin();
                sort = "0";
                deriction = "0";

                title_type = 2;
                if (TextUtils.equals(account_type, "1")) {
                    tv_public.setVisibility(View.VISIBLE);
                } else {
                    tv_public.setVisibility(View.GONE);
                }
                //            setRightShow(0, R.string.fabu);
                // 0全部2加工订单3机床耗材4机床配件5机床组立6二手设备买卖7二手设备改造
                // 0全部1设备维修2机床耗材3机床组立4机床配件5加工订单6二手货设备买卖7二手货设置改造
                //TODO：
                if (type_id == 1) {
                    type_id_need = 1;
                } else if (type_id == 2) {
                    type_id_need = 5;
                } else if (type_id == 3) {
                    type_id_need = 2;
                } else if (type_id == 4) {
                    type_id_need = 4;
                } else if (type_id == 5) {
                    type_id_need = 3;
                } else if (type_id == 6) {
                    type_id_need = 6;
                } else if (type_id == 7) {
                    type_id_need = 7;
                }
                adapter.setType(title_type);
                isFrist = true;
                page = 1;
                httpGetdemand_list(Constant.Getdemand_list);
                break;
            //距离
            case R.id.distance:
                if (isDistance) {
                    //距离
                    distance_up.setImageResource(R.mipmap.img33);
                    distance_down.setImageResource(R.mipmap.img34_1);
                    //信誉
                    reputation_up.setImageResource(R.mipmap.img33_1);
                    reputation_down.setImageResource(R.mipmap.img34);
                    //评价
                    evaluate_up.setImageResource(R.mipmap.img33_1);
                    evaluate_down.setImageResource(R.mipmap.img34);
                    deriction = "1";
                } else {
                    deriction = "2";
                    initBigin();

                }
                isDistance = !isDistance;
                isReputation = true;
                isEvaluate = true;
                sort = "1";
                if (title_type == 1) {
                    httpGetdemand_list(Constant.Getservice_list);
                } else if (title_type == 2) {
                    httpGetdemand_list(Constant.Getdemand_list);
                }
                break;
            //信誉
            case R.id.reputation:
                if (isReputation) {
                    //距离
                    distance_up.setImageResource(R.mipmap.img33_1);
                    distance_down.setImageResource(R.mipmap.img34);
                    //信誉
                    reputation_up.setImageResource(R.mipmap.img33);
                    reputation_down.setImageResource(R.mipmap.img34_1);
                    //评价
                    evaluate_up.setImageResource(R.mipmap.img33_1);
                    evaluate_down.setImageResource(R.mipmap.img34);
                    deriction = "1";
                } else {
                    deriction = "2";
                    //距离
                    initBigin();
                }
                isReputation = !isReputation;
                isDistance = true;
                isEvaluate = true;
                sort = "2";
                if (title_type == 1) {
                    httpGetdemand_list(Constant.Getservice_list);
                } else if (title_type == 2) {
                    httpGetdemand_list(Constant.Getdemand_list);
                }
                break;
            //评价
            case R.id.evaluate:
                if (isEvaluate) {
                    //距离
                    distance_up.setImageResource(R.mipmap.img33_1);
                    distance_down.setImageResource(R.mipmap.img34);
                    //信誉
                    reputation_up.setImageResource(R.mipmap.img33_1);
                    reputation_down.setImageResource(R.mipmap.img34);
                    //评价
                    evaluate_up.setImageResource(R.mipmap.img33);
                    evaluate_down.setImageResource(R.mipmap.img34_1);
                    deriction = "1";
                } else {
                    deriction = "2";
                    //距离
                    initBigin();
                }
                isEvaluate = !isEvaluate;
                isDistance = true;
                isReputation = true;
                sort = "3";

                if (title_type == 1) {
                    httpGetdemand_list(Constant.Getservice_list);
                } else if (title_type == 2) {
                    httpGetdemand_list(Constant.Getdemand_list);
                }
                break;
        }

    }

    private void httpGetdemand_list(String url) {
        int type_id = 0;
        if (title_type == 1) {
            type_id = type_id_ser;
        } else if (title_type == 2) {
            type_id = type_id_need;
        }


        List<NameValuePairSign> list = new ArrayList<NameValuePairSign>();
        list.add(new NameValuePairSign("type", type_id + ""));
        list.add(new NameValuePairSign("name", search_et.getText().toString()));
        list.add(new NameValuePairSign("address", PreferenceUtils.getPrefString("location_city", "")));

        list.add(new NameValuePairSign("longitude", mLongitude));
        list.add(new NameValuePairSign("latitude", mLatitude));
        list.add(new NameValuePairSign("sx_type", sort));
        list.add(new NameValuePairSign("deriction", deriction));


        list.add(new NameValuePairSign("page", page + ""));
        list.add(new NameValuePairSign("pagesize", Constant.PageSize));
        String sign = GetSign.genPackageSign(list);

        RequestParams params = new RequestParams();
        params.addQueryStringParameter("type", type_id + "");
        params.addQueryStringParameter("name", search_et.getText().toString());
        params.addQueryStringParameter("address", PreferenceUtils.getPrefString("location_city", ""));


        params.addQueryStringParameter("longitude", mLongitude);
        params.addQueryStringParameter("latitude", mLatitude);
        params.addQueryStringParameter("sx_type", sort);
        params.addQueryStringParameter("deriction", deriction);


        params.addQueryStringParameter("page", page + "");
        params.addQueryStringParameter("pagesize", Constant.PageSize);
        params.addQueryStringParameter("sign", sign);


        System.out.println(mLongitude);
        HttpUtilsSingle.doGet(this, false, url, params, new RequestCallBack<String>() {
            @Override
            public void onSuccess(ResponseInfo<String> arg0) {
                String result = arg0.result.toString();
                List<FacilityMainenanceModel> new_list = new ArrayList<FacilityMainenanceModel>();
                try {
                    JSONObject json = new JSONObject(result);
                    String Errcode = json.getString("ErrCode");
                    String Errmsg = json.getString("ErrMsg");
                    String Response = json.getString("Response");
                    Gson gson = new Gson();
                    switch (Integer.valueOf(Errcode)) {
                        case 1:// 失败
                            ToastUtils.showToast(Errmsg);
                            pull_to_refresh_scrollview.onPullDownRefreshComplete();
                            pull_to_refresh_scrollview.onPullUpRefreshComplete();
                            //                            new_list = new ArrayList<FacilityMainenanceModel>();
                            hindDailog();
                            break;
                        case 0:// 成功
                            new_list = gson.fromJson(Response,
                                    new TypeToken<List<FacilityMainenanceModel>>() {
                                    }.getType());
                            hindDailog();
                            break;
                        case 2:// 暂无内容
                            pull_to_refresh_scrollview.onPullDownRefreshComplete();
                            pull_to_refresh_scrollview.onPullUpRefreshComplete();
                            //                            new_list = new ArrayList<FacilityMainenanceModel>();
                            hindDailog();
                            break;
                    }
                    if (isFrist) {

                        if (isNullDate(new_list)) {
                            adapter.setList(new_list);
                            adapter.notifyDataSetChanged();
                        }
                        pull_to_refresh_scrollview.onPullDownRefreshComplete();

                    } else {
                        List<FacilityMainenanceModel> allList = adapter.getList();
                        allList.addAll(new_list);
                        adapter.setList(allList);
                        adapter.notifyDataSetChanged();
                        pull_to_refresh_scrollview.onPullUpRefreshComplete();
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(HttpException arg0, String arg1) {
                ToastUtils.showToast("获取数据失败,请检查网络");
                hindDailog();
            }
        });
    }

    /**
     * @tab 判断listview是否有值
     */
    private boolean isNullDate(List<FacilityMainenanceModel> rewordList) {
        if (rewordList == null || rewordList.size() == 0) {
            null_information_layout.setVisibility(View.VISIBLE);
            listView.setVisibility(View.GONE);
            return false;
        } else {
            null_information_layout.setVisibility(View.GONE);
            listView.setVisibility(View.VISIBLE);
            return true;
        }
    }

    // 发布成功返回刷新
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == 15 && resultCode == 1) {
            isFrist = true;
            page = 1;
            if (title_type == 1) {
                httpGetdemand_list(Constant.Getservice_list);
            } else if (title_type == 2) {
                httpGetdemand_list(Constant.Getdemand_list);
            }
        }
        super.onActivityResult(requestCode, resultCode, data);
    }

    @Override
    public void onPullDownToRefresh(PullToRefreshBase<ScrollView> refreshView) {
        pull_to_refresh_scrollview.setLastUpdatedLabel(DateTimeUtil
                .getFormatDateTime(DateTimeUtil.getCurrTimestamp()));
        isFrist = true;
        page = 1;
        if (title_type == 1) {
            httpGetdemand_list(Constant.Getservice_list);
        } else if (title_type == 2) {
            httpGetdemand_list(Constant.Getdemand_list);
        }
    }

    @Override
    public void onPullUpToRefresh(PullToRefreshBase<ScrollView> refreshView) {
        pull_to_refresh_scrollview.setLastUpdatedLabel(DateTimeUtil
                .getFormatDateTime(DateTimeUtil.getCurrTimestamp()));
        isFrist = false;
        page++;
        if (title_type == 1) {
            httpGetdemand_list(Constant.Getservice_list);
        } else if (title_type == 2) {
            httpGetdemand_list(Constant.Getdemand_list);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

    }

    @Override
    public void onBackPressed() {
        Intent intent = new Intent();
        intent.setClass(QFacilityMaintenanceActivity.this, MianButtonActivity.class);
        startActivity(intent);
        finish();
    }
}
